package com.bestsoft.web.controller.picCategory;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestsoft.common.annotation.Log;
import com.bestsoft.common.core.controller.BaseController;
import com.bestsoft.common.core.domain.AjaxResult;
import com.bestsoft.common.enums.BusinessType;
import com.bestsoft.common.utils.poi.ExcelUtil;
import com.bestsoft.flow.domain.MenuCategory;
import com.bestsoft.flow.domain.PicUpload;
import com.bestsoft.flow.service.IPicUploadService;
import com.bestsoft.common.core.page.TableDataInfo;

/**
 * 图片分类管理Controller
 * 
 * @author ruoyi
 * @date 2023-08-04
 */
@RestController
@RequestMapping("/pic/uploadCategory")
public class PicUploadController extends BaseController {
    @Autowired
    private IPicUploadService tblPicCategoryService;

    /**
     * 查询图片分类菜单管理列表
     */
    // @PreAuthorize("@ss.hasPermi('system:category:menu')")
    @PostMapping("/menu")
    public TableDataInfo menuList(@RequestBody MenuCategory menuCategory) {
        List<MenuCategory> list = tblPicCategoryService.selectMenuCategory(menuCategory);
        return getDataTable(list);
    }

    /**
     * 查询图片分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:uploadCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(PicUpload tblPicCategory) {
        startPage();
        List<PicUpload> list = tblPicCategoryService.selectTblPicCategoryList(tblPicCategory);
        return getDataTable(list);
    }

    /**
     * 导出图片分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:uploadCategory:export')")
    @Log(title = "图片分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PicUpload tblPicCategory) {
        List<PicUpload> list = tblPicCategoryService.selectTblPicCategoryList(tblPicCategory);
        ExcelUtil<PicUpload> util = new ExcelUtil<PicUpload>(PicUpload.class);
        util.exportExcel(response, list, "图片分类管理数据");
    }

    /**
     * 获取图片分类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:uploadCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tblPicCategoryService.selectTblPicCategoryById(id));
    }

    /**
     * 新增图片分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:uploadCategory:add')")
    @Log(title = "图片分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PicUpload tblPicCategory) {
        return toAjax(tblPicCategoryService.insertTblPicCategory(tblPicCategory));
    }

    /**
     * 修改图片分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:uploadCategory:edit')")
    @Log(title = "图片分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PicUpload tblPicCategory) {
        return toAjax(tblPicCategoryService.updateTblPicCategory(tblPicCategory));
    }

    /**
     * 删除图片分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:uploadCategory:remove')")
    @Log(title = "图片分类管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tblPicCategoryService.deleteTblPicCategoryByIds(ids));
    }

}
